<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>点我发送jsonp请求</button>
    <div>
        <img src="" alt="">
    </div>
    <script>
        function myfn(res){
            let imgEle = document.querySelector("img");
            console.log("回调函数执行了",res);
            imgEle.src = res['img']
        }
        document.querySelector("button").onclick = function (){
            let s = document.createElement("script");
            s.src = "http://localhost/PHPcode/php-code/phpDay08/html/jsonp.php?callback=myfn" ;
            document.head.appendChild(s);
        }
    </script>
</body>
</html>